package com.tan.apps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.tan.apps.model.User;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public ModelAndView home(Locale locale) {
		logger.info("Welcome home! The client locale is {}.", locale);
		
		User user1 = new User();
		  user1.setUserName("A");

		   
		  User user2 = new User();
		  user2.setUserName("user2");

		   
		  List<User> lstUser = new ArrayList<User>();
		  lstUser.add(user1);
		  lstUser.add(user2);
		   
		  Map<String, List<User>> model = new HashMap<String, List<User>>();
		  model.put("users", lstUser);		
		  return new ModelAndView("home", model);
	}
	
}
